package com.example.project.controller;

import com.example.project.entity.Leaves;
import com.example.project.entity.Offduty;
import com.example.project.service.IOffdutyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "销假信息表")
@RestController
public class OffdutyController {
    @Autowired
    private IOffdutyService offdutyService;
    @CrossOrigin

    @ApiOperation(value = "对销假信息的添加")
    @GetMapping("getaddOffduty")
    public int insert(Offduty offduty){
        System.out.println("进入增加销假信息方法");
        return offdutyService.add(offduty);
    }

    @ApiOperation(value = "查询所有销假信息方法")
    @GetMapping("/getallOffduty")
    public List<Offduty> getAllOffduty(Offduty offduty){
        System.out.println("进入查询所有销假信息的方法");
        List<Offduty> offdutyList=offdutyService.getAllOffduty(offduty);
        return offdutyList;
    }

    @ApiOperation(value = "删除单条销假信息")
    @GetMapping("/deleteOffduty")
    public int deleteOffduty(int id){
        System.out.println("进入销假信息删除方法");
        int returnValus=0;
        if(id!=0){
            Offduty offduty=new Offduty();
            offduty.setOffDutyId(id);
            returnValus= offdutyService.deleteOffduty(offduty);
        }
        return returnValus;
    }

    @ApiOperation(value = "对销假信息更新方法")
    @GetMapping("/updateOffduty")
    public int updateOffduty(Offduty offduty){
        System.out.println("进入销假信息更新方法");
        return offdutyService.updateOffduty(offduty);
    }

    @ApiOperation(value = "获取单条销假数据")
    @GetMapping("/getoneOffduty")
    public Offduty getOffduty(int id){
        Offduty offduty=new Offduty();
        System.out.println("进入获取单条销假信息数据方法");
        if(id!=0){
            Offduty offduty1=new Offduty();
            offduty1.setOffDutyId(id);
            offduty=offdutyService.getOffduty(offduty1);
            System.out.println(""+offduty.getOffDutyId());
        }
        return offduty;
    }
}
